package cn.laixueit.cart.controller;

import cn.laixueit.cart.pojo.Cart;
import cn.laixueit.cart.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Controller
public class CartController {

    @Autowired
    private CartService cartService;

    @PostMapping
    public ResponseEntity<Void> cart(@RequestBody Cart cart){
        cartService.cart(cart);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/cart")
    public ResponseEntity<List<Cart>> listCart(){
        List<Cart> carts =  cartService.listCart();
        return ResponseEntity.ok(carts);
    }
}
